import React from 'react';
import { connect } from 'dva';
import { createForm } from 'rc-form';
import styles from './index.less';
import {Toast,List,InputItem,Button,Modal,WingBlank,WhiteSpace} from 'antd-mobile';
import {routerRedux} from 'dva/router';
import Block from 'fs-flex'
import Header from '../../../../../components/Header/index'
import BusiTypeService from '../../../../../services/busiTypeService'
const alert = Modal.alert
class SettingPage extends React.Component{
  state={
      show:false,
  }
    componentDidMount(){
    }
    async save(){
        if(this.props.location.state.data){
            //更新
            let data = this.props.form.getFieldsValue()
            data['id'] = this.props.location.state.data.id
            data['sysType'] = this.props.location.state.data.sysType
            data['note'] = this.props.location.state.data.note
            const {code,msg}=await BusiTypeService.updateBusiType(data)
            if(code==="0000"){
                Toast.info("更新成功！",2)
                setTimeout(() => {
                    this.props.history.goBack()
                }, 2000);
            }else{
                Toast.info(msg,3)
            }
        }else{
            //新增
            let data = this.props.form.getFieldsValue()
            const {code,msg}= await BusiTypeService.addBusiType(data)
            if(code==="0000"){
                Toast.info("添加成功！",3)
                setTimeout(() => {
                    this.props.history.goBack()
                }, 2000);
            }else{
                Toast.info(msg,3)
            }
        }
    }
  
  render(){
      const { getFieldProps  } = this.props.form;
    return (
      <Block vf>
        <Block>
          <Header title='业务范围编辑' needBack="true" history={this.props.history}/>
        </Block>
        <WingBlank size="lg">
            <WhiteSpace size="lg" />
                <List>
                    <List.Item>
                        <InputItem
                            {...getFieldProps('sys_value', { initialValue:this.props.location.state && this.props.location.state.data?this.props.location.state.data.sysValue:"" })}
                            clear
                            placeholder="请输入业务范围名称"
                            ref={el => this.autoFocusInst = el}
                        >业务范围名称</InputItem>
                    </List.Item>
                </List>
            <WhiteSpace size="lg" />
            <Block wf mt={15}>
                <Block f='3'></Block>
                <Block f='4'><Button a='c' f='c' size='small' type="primary" onClick={() =>
                        this.save()}
                    >保存</Button></Block>
                <Block f='3'></Block>
            </Block>
        </WingBlank>
      </Block>
    );
  }
  
}

SettingPage
.propTypes = {
};

export default createForm()(connect()(SettingPage));
